﻿#region Header

/*
    This file is part of nDoctor Light

    NDoctor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    NDoctor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with NDoctor.  If not, see <http://www.gnu.org/licenses/>.
*/

#endregion Header

namespace Probel.Ldoc.Views.Pages
{
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;

    using Probel.Ldoc.ViewModels.Pages;
    using Probel.Mvvm.Gui;

    /// <summary>
    /// Interaction logic for SearchView.xaml
    /// </summary>
    public partial class SearchView : Page
    {
        #region Constructors

        public SearchView(SearchViewModel viewmodel)
        {
            InitializeComponent();
            this.DataContext = viewmodel;
        }

        #endregion Constructors

        #region Properties

        private SearchViewModel ViewModel
        {
            get { return this.DataContext as SearchViewModel; }
        }

        #endregion Properties

        #region Methods

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            Keyboard.Focus(this.focused);
        }

        private void ResultList_Click(object sender, MouseButtonEventArgs e)
        {
            var item = this.resultList.SelectedItem;

            if (ApplicationCommands.Open.CanExecute(item, this))
            {
                ApplicationCommands.Open.Execute(item, this);
            }
        }

        #endregion Methods
    }
}